<?php
/*
Cogumelo v0.2 - Innoto S.L.
Copyright (C) 2010 Innoto Gestión para el Desarrollo Social S.L. <mapinfo@map-experience.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
USA.
*/

class C_ClassLoader
{
	const path = "Classes/"; 
	private static $fileindex = array(
		// View Classes
		'Smarty' => 'Utils/Vendor/Smarty-3.0.5/libs/Smarty.class.php',
		'Template' => 'View/Template.inc',
		// Tables
		'abstractTable' => 'View/table/abstractTable.inc',
			'tableCol' => 'View/table/tableCol.inc',
			'genericTableCol' => 'View/table/genericTableCol.inc',
			'abstractTableFilter' => 'View/table/abstractTableFilter.inc',
			'exampleTable' => 'View/table/exampleTable.inc',

		// Mailing Classes
		'PHPMailer' => 'Utils/Vendor/PHPMailer_v5.1/class.phpmailer.php',	
		'MailSender' => 'Controllers/Mail/MailSender.inc',
		'MailController' => 'Controllers/Mail/MailController.inc',
		
		// Controller Classes
	
		'LangController' => 'Controllers/Language/LangController.inc',
	
		'SessionController' => 'Controllers/Session/SessionController.inc',
			'LangSessionController' => 'Controllers/Session/LangSessionController.inc',
	
		'DataController' => 'Controllers/Data/DataController.inc',
	
		'FormProc' => 'Controllers/Validation/FormProc.inc',
		
		'QuickForm' => 'Controllers/Validation/QuickForm.inc',
	
		'AccessController' => 'Controllers/Access/AccessController.inc',
	
		// Gettext controllers
		'Gettext' => 'Utils/Vendor/Gettext/gettext.inc',
		
		// Model Core Classes
		'Facade' => 'Model/Core/Facade.inc',
		'Connection' => 'Model/Core/Connection.inc',
		'DAO' => 'Model/Core/DAO.inc',
		'VO' => 'Model/Core/VO.inc', 
		
		// Model Mysql Classes
		'MysqlConnection' => 'Model/Mysql/MysqlConnection.inc',
		'MysqlDAOutils' => 'Model/Mysql/MysqlDAOutils.inc',


		// Utils
		'Utils' => 'Utils/Utils.inc',
		'Singleton' => 'Utils/Singleton.inc',
		'geography-countries' => 'Utils/geography/countries.inc',
			'geography-ccaa' => 'Utils/geography/ccaa.inc',
			'geography-provinces' => 'Utils/geography/provinces.inc',
			'geography-provinces_gz' => 'Utils/geography/provinces_gz.inc',
			'geography-concellos' => 'Utils/geography/concellos.inc',
			'geography-concellos_location' => 'Utils/geography/concellos_location.inc',
		'AuthCodeGenerator' => 'Utils/AuthCodeGenerator.inc',
		'XmlToArray' => 'Utils/XmlToArray.inc',
		'simpleCurl' => 'Utils/simpleCurl.inc',
		'Exp2XLS' => 'Utils/Exp2XLS.inc',
		'toPDF'=> 'Utils/Vendor/tcpdf/toPdf.php',
		'recaptcha' => 'Utils/recaptcha/recaptchalib.inc',
		// Core Classes
		'C_i18n' => 'C_i18n.inc',
		'C_RequestManager' => 'C_RequestManager.inc'
	);
	public static function Load($c)
	{
		$from = get_called_class();	
		$from = ( property_exists($from, 'fileindex') ) ? $from : 'C_ClassLoader';

		if( !$from::$fileindex[$c] )
			Cogumelo::Error("Class $c doesn't exist on $from::\$fileindex");
		
		require_once $from::path . $from::$fileindex[$c];
		return $c;
	}
}
